package com.ws.q1.mapper;


import com.ws.q1.bean.XianLu;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface XianLuMapper {
    @Select("SELECT tr.*, l.* " +
            "FROM travel_routes tr " +
            "LEFT JOIN lanmu l ON tr.Lid =  l.Lid")
    List<XianLu> list();


    @Delete("DELETE FROM travel_routes WHERE id = #{id}")
    void deleteById(Integer id);


    @Insert("INSERT INTO travel_routes (name, chufadi, mudidi, miaoshu, price, days, tou, gongyingshang_name, Lid, lunbo) VALUES (#{name}, #{chufadi}, #{mudidi}, #{miaoshu}, #{price}, #{days}, #{tou}, #{gongyingshang_name}, #{lid}, #{lunbo})")
    int add(XianLu xianlu);


    //修改
    @Update("update travel_routes set name=#{name}, chufadi=#{chufadi}, mudidi=#{mudidi}, miaoshu=#{miaoshu}, price=#{price}, days=#{days}, tou=#{tou}, gongyingshang_name=#{gongyingshang_name}, lanmu_name=#{lanmu_name}, lunbo=#{lunbo} where id=#{id}")
    int update(XianLu xianlu);


    @Select("select * from travel_routes where id=#{id}")
    XianLu huixian(Integer id);

    @Select("SELECT * FROM travel_routes WHERE " +
            "(#{name} IS NULL OR name LIKE CONCAT('%', #{name}, '%')) AND " +
            "(#{chufadi} IS NULL OR chufadi LIKE CONCAT('%', #{chufadi}, '%')) AND " +
            "(#{mudidi} IS NULL OR mudidi LIKE CONCAT('%', #{mudidi}, '%')) AND " +
            "(#{price} IS NULL OR price = #{price}) AND " +
            "(#{gongyingshangId} IS NULL OR gongyingshang_name = (SELECT name FROM gyshang WHERE id = #{gongyingshangId}))")
    List<XianLu> pageList(@Param("name") String name, @Param("chufadi") String chufadi, @Param("mudidi") String mudidi, @Param("price") Double price, @Param("gongyingshangId") Integer gongyingshangId);



}
